/*
 * @Author: gitee_com_zb
 * @Date: 2024-11-14 18:05:38
 * @LastEditors: gitee_com_zb
 * @LastEditTime: 2024-11-14 18:05:53
 * @FilePath: /lzb/GiteeCode/algorithm/优选算法39.提莫攻击(easy).cpp
 * @Description: 题目链接 https://leetcode.cn/problems/teemo-attacking
 */
class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration) {
        // 分情况讨论,
        // 两个时间之间差值大于等于duration,则持续时间是duration
        // 两个时间之间差值小于duration,则持续时间是两者差值
        // 注意最后一次攻击后的时间不要漏掉
        int time = 0;
        for(int i = 1; i < timeSeries.size(); i++) {
            int diff = timeSeries[i] - timeSeries[i-1];
            if(diff < duration) time += diff;
            else time += duration;
        }
        return time + duration;
    }
};